package com.qingke.action;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.qingke.dao.StrutsExampleDAO;
import com.qingke.pojo.Account;

public class LoginAction extends ActionSupport {
	private ActionContext ac=ActionContext.getContext();
	private StrutsExampleDAO dao=new StrutsExampleDAO();
	@Override
	public String execute() throws Exception {
		HttpServletRequest request=(HttpServletRequest) ac.get(ServletActionContext.HTTP_REQUEST);
		String username=request.getParameter("username");
		String password=request.getParameter("password");
		Account account=dao.login(username, password);
		if(account==null||!account.isAdmin())
			return ERROR;
		return SUCCESS;
	}
}
